package com.bwie.controller;

import com.bwie.pojo.Events;
import com.bwie.service.EventsService;
import com.bwie.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @description:
 * @author: ykk
 * @create: 2024-11-04 09:10
 **/
@RestController
@RequestMapping("/eventsList")
public class EventsController {

    @Autowired
    EventsService eventsService;


    /**
     * 查询优惠价活动列表
     * @return
     */
    @PostMapping("/list")
    public R list(){
      List<Events> list = eventsService.eventsListA();
      return R.OK(list);
    }

    /**
     * 添加优惠卷的信息
     * @param events
     * @return
     */
    @PostMapping("/addEvents")
    public R addEvents(@RequestBody Events events){
        Events events1 = new Events();
        events1.setRadius("全场通用");
        events1.setApplicableObject("全部用户");
        events1.setName(events.getName());
        events1.setTypeName(events.getTypeName());
        events1.setPrice(events.getPrice());
        events1.setBeginTime(events.getBeginTime());
        events1.setEndTime(events.getEndTime());
        events1.setNum(events.getNum());
        boolean save = eventsService.save(events1);
        return R.OK(save);
    }
}
